<?php

class FeedModel
{
    private $diaryListModel;
    private $autoUidModel;
    private $diaryListCacheModel;
    private $groupInfoModel;
    private $userStatisticsModel;
    private $voteModel;
    private $userStatisticsKeyPrefix    =   'US/';
    private $feedKeyPrefix              =   'F/';
    private $feedInfoKeyPrefix          =   'FO/';
    private $feedListKeyPrefix          =   'FL/';
    private $slaveKey                   =   '/slave';
    
    public function __construct(){
        $this->groupInfoModel       =   new GroupInfoModel();
        $this->diaryListModel       =   new DiaryListModel();
        $this->autoUidModel         =   new AutoUidModel();
        $this->diaryListCacheModel  =   new DiaryListCacheModel();
        $this->userStatisticsModel  =   new UserStatisticsModel();

		$this->voteModel            =   new VoteModel();
    }
    
    public function rebuildNoticeData($data){
    	$ownData =  array(
    	    'id'	=>0,
    	    'type'	=>'default',
    	    'time'	=>'',
    	    'uid'	=>'',
    	    'user'	=>array(),
    	    'data'	=>array(
    	        'title'		=>'',
    	        'content'	=>'',
    	        'action'	=>'',
    	        'image'		=>'',
    	    ),
    	    'quote' =>array(
    	        'uid' => '',
    	        'user'=> '',
    	        'data'=>array(
                    "title"		=> "",
                    "content"	=> "",
                    "type"		=> "",
                    "type_id"	=> "",
                    "attachment"=>array(
                        'attachmentList'=>array(
                             array(
                                 "id"				=>	"",
                                 "uid"				=>	"",
                                 "bodyId"			=>	"",
                                 "attachmentType"	=>	"",
                                 "attachmentPath" 	=>  "",
                                 "uploadTime"		=>  "",
                                 "status"			=>  "",
                                 "type"				=>  "",
                                 "type_id"			=>	"",
                                 "info"				=>	""
                             )
                        ),
                        'voiceList' => array(
                             array(
                                 "id"				=> "",
                                 "uid"				=> "",
                                 "bodyId"			=> "",
                                 "attachmentType"	=> "",
                                 "attachmentPath"	=> "",
                                 "uploadTime"		=> "",
                                 "status"			=> "",
                                 "type"				=> "",
                                 "type_id"			=> "",
                                 "info"				=> ""
                             )
                        )
                    )
    	        ),    		 					
    	    ),
    	);
    
 
    	if($data['verb'] == AC::FEED_ANNOUNCE){
            $userInfo = $this->autoUidModel->getUserInfo($data['uid']);
            $con      = json_decode($data['object'],true);
            if(empty($con)){
                AC::$errorNo = 'FMR001';
                return false;
            }
  		
            $ownData['id'] 		= $data['feed_id'];
            $ownData['type']	= 'system';
            $ownData['time']	= $data['time'];
            $ownData['uid']		= $data['uid'];
            $ownData['user']  	= empty($userInfo) ? array() : $userInfo;
            $ownData['data']    = array(
                'title'		=> $data['title'],
                'content'	=> $con['content'],
                'action'	=> $con['action'],
                'image'		=> strval($con['image'][0])   						
            );
            $ownData['data']['image'] = AC::getProtocolUriByOS($ownData['data']['image']);
		    		
            return $ownData;
    	}
	
    	return array();
    }
    
    /**
     * 更新读取公告时间重置轮询数字
     * @param unknown $uid
     */
    public function UpdateAnnounceData($uid){
    	//更新缓存最后读取公告时间时间
    	$time = AC::SERVER_TIME;
    	$this->diaryListCacheModel->updateUserFlushTimeCache($uid, array('ar_t' => $time));
    	
    	//更新数据库公告最后读取时间，重置公告轮询数字
    	$key    =   $this->userStatisticsKeyPrefix. $uid;
    	$data   =   array('newAnnounceTimes' => '0','readAnnounceTime'=>$time);
    	$result =   Storage::setData($key, $data);
    	return $result;
    }
  
    /**
    * 更新公告计数
    * @param unknown $uid
    */
    public function UpdateAnnounceCount($uid){
        if (empty($uid)) return  false;
        
        $announce = $this->confirmAnnounceCacheData();
        if (empty($announce)) return false;
        
        //取用户读取公告最新时间
        $time 	= $this->checkReadAnnounceTime($uid);
        $lists	= $this->diaryListCacheModel->getNewAnnounceList($time);
        if($lists){
            $key    =   $this->userStatisticsKeyPrefix. $uid;
            $data   =   array('newAnnounceTimes' => intval(count($lists)));
            $result =   Storage::setData($key, $data);
  			
            return  $result;
        }
  		
        return true;
    }
    
    /**
     * 获取用户读取公告的时间
     * @param unknown $uid
     * @return number
     */
    private function checkReadAnnounceTime ($uid) {
        if (empty($uid)) return 0;
        
        $flushTime = $this->diaryListCacheModel->getUserFlushTimeCache($uid);
        if (!isset($flushTime['ar_t']) || empty($flushTime['ar_t'])) {
            $data = $this->userStatisticsModel->getUserStatisticsByUid($uid);
            if($data){
                $flushTime['ar_t'] = $data['readAnnounceTime'];
                $this->diaryListCacheModel->updateUserFlushTimeCache($uid, array('ar_t' => $data['readAnnounceTime']));
            }
        }
    
        return intval($flushTime['ar_t']);
    }
    
    
    private function confirmAnnounceCacheData () {
        $result = $this->getAnnounceList(0, 1);
        return $result ? true : false;
    }
  	
    /**
     * 获取公告列表
     * @param unknown $id
     * @param unknown $length
     * @param number $uid
     * @return boolean|Ambigous <multitype:, unknown>
     */
    public function getAnnounceList ($id, $length, $uid = 1) {
        $result = $this->diaryListCacheModel->getAnnounceCache($id, $length);
        if (empty($id) && empty($result)) {
            $key 	 = 	$this->feedInfoKeyPrefix. $uid;
            $where   =  array('verb' => AC::FEED_ANNOUNCE, 'uid' => $uid);
            $orderBy =  ' time DESC ';
            $result  =  Storage::getConditionManyData($key, $where, $orderBy);
            if(empty($result)){
                return false;
            }
            
            $this->rebuildAnnounceListCache($result);
            $result = $this->getNewestAnnounceList($result, $length);
        }
        
        return $result;
    }
    
    /**
     * 重建公告缓存
     * @param unknown $list
     * @return boolean
     */
    private function rebuildAnnounceListCache ($list) {
        if (empty($list)) return false;
        
        foreach ($list as $value){
            //重建feedid列表
            $this->diaryListCacheModel->setAnnounceCache($value['feed_id'],$value['time']);
            
            //重建feedinfo信息
            $this->diaryListCacheModel->setFeedInfoCache($value['feed_id'], $value);
        }
        
        return true;
    }
    
    private function getNewestAnnounceList ($list, $length) {
        if (empty($list)) return array();
        
        $fids = array();
        foreach ($list as $value){		
            $fids[] = $value['feed_id'];
        }
        
        return array_slice($fids, 0, $length);
    }
    
    public function setFeedInfo ($feedInfo)
    {
        if (empty($feedInfo['uid']) ||  empty($feedInfo['eUid']) || strlen($feedInfo['eNickname'])< 1 )
        {
            AC::$errorNo    =   'FM001';
            return  FALSE;
        }

        if (empty($feedInfo['type']))
        {
            AC::$errorNo    =   'FM002';
            return  FALSE;
        }

        if ((AC::FEED_FOLLOW!=  $feedInfo['type'] && AC::FEED_REMOVEFOLLOW!= $feedInfo['type']) &&  empty($feedInfo['bodyId']))
        {
            AC::$errorNo    =   'FM007';
            return  FALSE;
        }

        isset($feedInfo['bodyId'])      &&  $data['bodyId']     =   $feedInfo['bodyId'];
        isset($feedInfo['content'])     &&  $data['content']    =   $feedInfo['content'];
        isset($feedInfo['subType'])     &&  $data['subType']    =   $feedInfo['subType'];
        isset($feedInfo['rUid'])        &&  $data['rUid']       =   $feedInfo['rUid'];
        isset($feedInfo['rNickname'])   &&  $data['rNickname']  =   $feedInfo['rNickname'];
        isset($feedInfo['parentId'])    &&  $data['parentId']   =   $feedInfo['parentId'];
        isset($feedInfo['position'])    &&  $data['position']   =   $feedInfo['position'];
        empty($data['rUid'])      && $data['rUid'] = '0';
        empty($data['rNickname']) && $data['rNickname'] = '';
        $data['uid']            =   $feedInfo['uid'];
        $data['eUid']           =   $feedInfo['eUid'];
        $data['eNickname']      =   $feedInfo['eNickname'];
        $data['authorUid']      =   $feedInfo['authorUid'];
        $data['authorNickname'] =   $feedInfo['authorNickname'];
        $data['type']           =   $feedInfo['type'];
        $data['time']           =   AC::SERVER_TIME;
	
        $feed_me = $data;
        if ($feed_me['parentId'] && $feed_me['rUid']){
            $feed_me['uid'] = $feed_me['rUid'];
        }else{
            $feed_me['uid'] = $feedInfo['authorUid'];
        }
        
        // 异步写动态
        $feedInfo['extra'] = $data;
        $feedId = $this->addFeedInfo($feedInfo);

        // 写通知
        $noticeInfo = array(
                'uid'        =>    $feedInfo['authorUid'],
                'type_id'    =>    $feedId,
                'time'       =>    AC::SERVER_TIME 
        );
        if ($data['parentId'] && $data['rUid']){
            $noticeInfo['uid'] = $data['rUid'];
        }
        if ($noticeInfo['uid'] != AC::HOST_UID){
            $result = $this->addNoticeInfo($noticeInfo);
        }
        
        return  $result;
    }/*}}}*/
    
    public function addNoticeInfo($noticeInfo) {
        $data    =    $noticeInfo;
        $key     =    $this->feedListKeyPrefix. $noticeInfo['uid'];
        $result  =    Storage::addData($key, $data);
        
        if (empty($result)){
            UK::varDump(AC::$errorNo, __METHOD__);
            return  FALSE;
        }
        
        // 异步任务json数据
        $post_feed_me = array(
                'uid'    =>    strval($noticeInfo['uid']),
                'feedId' =>    strval($noticeInfo['type_id'])
        );
        $post_feed_me_json = json_encode($post_feed_me);
        RedisPool::addFeedGearmanJob("postfeedme", $post_feed_me_json);
        
        return TRUE;
    }
    
    public function addFeedInfo ($feedInfo)
    {
        /**
            const   FEED_DIARY               =   1;
            const   FEED_FOLLOW             =   16;
            const   FEED_COMMENT           =   17;
            const   FEED_LIKE                 =   18;
            const   FEED_SHARE               =   19;
            const   FEED_KIT_ANNIVERSARY    =   12;
            const   FEED_KIT_BMI            =   14;
            const   FEED_KIT_MENSES      =   15;
            const   FEED_KIT_NOTE          =   9;
            const   FEED_KIT_SCHEDULE  =   10;
            const   FEED_KIT_TALLYBOOK=   8;
            const   FEED_REPOST              =   21;
            const   FEED_TOPIC                =   22;
            const   FEED_TOPIC_REPLY    =   23;
         */
        
        $data = array();
        if($feedInfo['type'] ==  AC::FEED_DIARY){
            return FALSE;
            $data =  $this->diaryFeed($feedInfo);
        }elseif($feedInfo['type'] ==  AC::FEED_FOLLOW){
            $data =  $this->followFeed($feedInfo);
        }elseif($feedInfo['type'] ==  AC::FEED_REMOVEFOLLOW){
			$data =  $this->followFeed($feedInfo);
		}elseif($feedInfo['type'] ==  AC::FEED_COMMENT){
            $data =  $this->commentFeed($feedInfo);
        }elseif($feedInfo['type'] ==  AC::FEED_LIKE){
            $data =  $this->likeFeed($feedInfo);
        }elseif($feedInfo['type'] ==  AC::FEED_REPOST){
            return FALSE;
            $data =  $this->repostFeed($feedInfo);
        }elseif($feedInfo['type'] ==  AC::FEED_TOPIC){
            return FALSE;
            $data =  $this->topicFeed($feedInfo);
        }elseif($feedInfo['type'] ==  AC::FEED_TOPIC_REPLY){
            return FALSE;
            $data =  $this->replyFeed($feedInfo);
        }else{
            return FALSE;
            $data =  $this->diaryFeed($feedInfo);
        }

        $key    =   $this->feedInfoKeyPrefix. $feedInfo['uid'];
        $fid    =   Storage::addData($key, $data);
        
        if (empty($fid))
        {
            UK::varDump(AC::$errorNo, __METHOD__);
            return  FALSE;
        }

        $feedId =   $this->getFeedInfoId($feedInfo['uid'], $fid);
        
        $where  =   array('id' => $fid, 'uid'=>$data['uid']);
        $result =   Storage::setConditionData($key, array('feed_id'=>$feedId), $where);
        if (empty($result))
        {
            UK::varDump(AC::$errorNo, __METHOD__);
            return  FALSE;
        }
        
        $this->diaryListCacheModel->setFeedInfoCache($feedId, $data);
        
        // 异步任务json数据
        $post_feed_data = array(
                'uid'    =>    strval($data['uid']),
                'feedId' =>    strval($feedId),
        );
        $post_feed_json = json_encode($post_feed_data);
        if($feedInfo['type'] !=  AC::FEED_REMOVEFOLLOW){
			RedisPool::addFeedGearmanJob("postfeed", $post_feed_json);
		}
        return $feedId;
    }
    
    private function diaryFeed($feedInfo){
        
        $extra = array();
        $extra['bodyId']     =  intval($feedInfo['bodyId']);
        isset($feedInfo['bodyId'])      &&  $extra['bodyId']     =   $feedInfo['bodyId'];
        isset($feedInfo['content'])     &&  $extra['content']    =   $feedInfo['content'];
        isset($feedInfo['subType'])     &&  $extra['subType']    =   $feedInfo['subType'];
        isset($feedInfo['rUid'])        &&  $extra['rUid']       =   $feedInfo['rUid'];
        isset($feedInfo['rNickname'])   &&  $extra['rNickname']  =   $feedInfo['rNickname'];
        isset($feedInfo['parentId'])    &&  $extra['parentId']   =   $feedInfo['parentId'];
        isset($feedInfo['eUid'])    &&  $extra['eUid']   =   $feedInfo['eUid'];
        isset($feedInfo['eNickname'])    &&  $extra['eNickname']   =   $feedInfo['eNickname'];
        isset($feedInfo['authorUid'])    &&  $extra['authorUid']   =   $feedInfo['authorUid'];
        isset($feedInfo['authorNickname'])    &&  $extra['authorNickname']   =   $feedInfo['authorNickname'];
        
        $object = array();
        $object['uid']  =   $feedInfo['authorUid'];
        $object['nickname']  =   $feedInfo['authorNickname'];
        $object['bodyId']      =    $feedInfo['bodyId'];
            
        $actor = array();
        $actor['uid']            =   $feedInfo['eUid'];
        $actor['nickname']  =   $feedInfo['eNickname'];
            
        $data = array();
        $data['uid']         =  $feedInfo['uid'];
        $data['verb']         =  $feedInfo['type'];
        $data['target']         =  0;
        $data['title']         =  $feedInfo['content'];
        $data['summary']         =  "";
        $data['time']         =  AC::SERVER_TIME;
        $data['actor']         = UK::var_json_encode($actor);
        $data['object']         =  UK::var_json_encode($object);
        $data['extra']         =  UK::var_json_encode($feedInfo['extra']);
        
        return $data;
    }
    
    private function followFeed($feedInfo){
        $extra = array();
        $extra['bodyId']     =  intval($feedInfo['bodyId']);
        isset($feedInfo['bodyId'])      &&  $extra['bodyId']     =   $feedInfo['bodyId'];
        isset($feedInfo['content'])     &&  $extra['content']    =   $feedInfo['content'];
        isset($feedInfo['subType'])     &&  $extra['subType']    =   $feedInfo['subType'];
        isset($feedInfo['rUid'])        &&  $extra['rUid']       =   $feedInfo['rUid'];
        isset($feedInfo['rNickname'])   &&  $extra['rNickname']  =   $feedInfo['rNickname'];
        isset($feedInfo['parentId'])    &&  $extra['parentId']   =   $feedInfo['parentId'];
        isset($feedInfo['eUid'])    &&  $extra['eUid']   =   $feedInfo['eUid'];
        isset($feedInfo['eNickname'])    &&  $extra['eNickname']   =   $feedInfo['eNickname'];
        isset($feedInfo['authorUid'])    &&  $extra['authorUid']   =   $feedInfo['authorUid'];
        isset($feedInfo['authorNickname'])    &&  $extra['authorNickname']   =   $feedInfo['authorNickname'];
        
        $object = array();
        $actor['uid']            =   $feedInfo['authorUid'];
        $actor['nickname']  =   $feedInfo['authorNickname'];
            
        $actor = array();
        $actor['uid']            =   $feedInfo['eUid'];
        $actor['nickname']  =   $feedInfo['eNickname'];
            
        $data = array();
        $data['uid']         =  $feedInfo['uid'];
        $data['verb']         =  $feedInfo['type'];
        $data['target']         =  0;
        $data['title']         =  $feedInfo['content'];
        $data['summary']         =  "";
        $data['time']         =  AC::SERVER_TIME;
        $data['actor']         = UK::var_json_encode($actor);
        $data['object']         =  UK::var_json_encode($object);
        $data['extra']         =  UK::var_json_encode($feedInfo['extra']);
        
        return $data;
    }
    
    private function commentFeed($feedInfo){
        $extra = array();
        $extra['bodyId']     =  intval($feedInfo['bodyId']);
        isset($feedInfo['bodyId'])      &&  $extra['bodyId']     =   $feedInfo['bodyId'];
        isset($feedInfo['content'])     &&  $extra['content']    =   $feedInfo['content'];
        isset($feedInfo['subType'])     &&  $extra['subType']    =   $feedInfo['subType'];
        isset($feedInfo['rUid'])        &&  $extra['rUid']       =   $feedInfo['rUid'];
        isset($feedInfo['rNickname'])   &&  $extra['rNickname']  =   $feedInfo['rNickname'];
        isset($feedInfo['parentId'])    &&  $extra['parentId']   =   $feedInfo['parentId'];
        isset($feedInfo['position'])    &&  $extra['position']   =   $feedInfo['position'];
        isset($feedInfo['eUid'])    &&  $extra['eUid']   =   $feedInfo['eUid'];
        isset($feedInfo['eNickname'])    &&  $extra['eNickname']   =   $feedInfo['eNickname'];
        isset($feedInfo['authorUid'])    &&  $extra['authorUid']   =   $feedInfo['authorUid'];
        isset($feedInfo['authorNickname'])    &&  $extra['authorNickname']   =   $feedInfo['authorNickname'];
        
        $object = array();
        $object['uid']  =   $feedInfo['authorUid'];
        $object['nickname']  =   $feedInfo['authorNickname'];
        $object['bodyId']      =    $feedInfo['bodyId'];
        $object['parentId']      =    intval($feedInfo['parentId']);
        $object['quote']      =    $feedInfo['quote'];
        
        $actor = array();
        $actor['uid']            =   $feedInfo['eUid'];
        $actor['nickname']  =   $feedInfo['eNickname'];
            
        $data = array();
        $data['uid']         =  $feedInfo['uid'];
        $data['verb']         =  $feedInfo['type'];
        $data['target']         =  0;
        $data['title']         =  $feedInfo['content'];
        $data['summary']         =  "";
        $data['time']         =  AC::SERVER_TIME;
        $data['actor']         = UK::var_json_encode($actor);
        $data['object']         =  UK::var_json_encode($object);
        $data['extra']         =  UK::var_json_encode($feedInfo['extra']);
        
        return $data;
    }
    
    private function likeFeed($feedInfo){
        $extra = array();
        $extra['bodyId']     =  intval($feedInfo['bodyId']);
        isset($feedInfo['bodyId'])      &&  $extra['bodyId']     =   $feedInfo['bodyId'];
        isset($feedInfo['content'])     &&  $extra['content']    =   $feedInfo['content'];
        isset($feedInfo['subType'])     &&  $extra['subType']    =   $feedInfo['subType'];
        isset($feedInfo['rUid'])        &&  $extra['rUid']       =   $feedInfo['rUid'];
        isset($feedInfo['rNickname'])   &&  $extra['rNickname']  =   $feedInfo['rNickname'];
        isset($feedInfo['parentId'])    &&  $extra['parentId']   =   $feedInfo['parentId'];
        isset($feedInfo['eUid'])    &&  $extra['eUid']   =   $feedInfo['eUid'];
        isset($feedInfo['eNickname'])    &&  $extra['eNickname']   =   $feedInfo['eNickname'];
        isset($feedInfo['authorUid'])    &&  $extra['authorUid']   =   $feedInfo['authorUid'];
        isset($feedInfo['authorNickname'])    &&  $extra['authorNickname']   =   $feedInfo['authorNickname'];
        
        $object = array();
        $object['uid']  =   $feedInfo['authorUid'];
        $object['nickname']  =   $feedInfo['authorNickname'];
        $object['bodyId']      =    $feedInfo['bodyId'];
            
        $actor = array();
        $actor['uid']            =   $feedInfo['eUid'];
        $actor['nickname']  =   $feedInfo['eNickname'];
            
        $data = array();
        $data['uid']         =  $feedInfo['uid'];
        $data['verb']         =  $feedInfo['type'];
        $data['target']         =  0;
        $data['title']         =  $feedInfo['content'];
        $data['summary']         =  "";
        $data['time']         =  AC::SERVER_TIME;
        $data['actor']         = UK::var_json_encode($actor);
        $data['object']         =  UK::var_json_encode($object);
        $data['extra']         =  UK::var_json_encode($feedInfo['extra']);
        
        return $data;
    }
    
    private function topicFeed($feedInfo){
        $data = array();
        
        return $data;
    }
    
    private function replyFeed($feedInfo){
        $data = array();
        
        return $data;
    }

    public function getFeedInfoId($uid, $fid)/*{{{*/
    {
        $key    =   $this->feedInfoKeyPrefix. $uid;
        $feedId =   UK::getBodyidByItemid($key, $fid);

        if (empty($feedId))
        {
            AC::$errorNo    =   'DBM003';
            return  FALSE;
        }
        return  $feedId;
    }
  
    #添加提及我信息
    public function setMentionInfo($feedInfo,$uid)/*{{{*/
    {
        isset($feedInfo['bodyId'])      &&  $data['bodyId']     =   $feedInfo['bodyId'];
        isset($feedInfo['content'])     &&  $data['content']    =   $feedInfo['content'];
        isset($feedInfo['subType'])     &&  $data['subType']    =   $feedInfo['subType'];
        isset($feedInfo['rUid'])        &&  $data['rUid']       =   $feedInfo['rUid'];
        isset($feedInfo['rNickname'])   &&  $data['rNickname']  =   $feedInfo['rNickname'];
        isset($feedInfo['parentId'])    &&  $data['parentId']   =   $feedInfo['parentId'];
        
        $data['uid']            =   $uid;
    	$data['eUid']           =   $feedInfo['eUid'];
    	$data['eNickname']      =   $feedInfo['eNickname'];
    	$data['authorUid']      =   $feedInfo['authorUid'];
    	$data['authorNickname'] =   $feedInfo['authorNickname'];
    	$data['type']           =   AC::FEED_MENTION;
    	$data['time']           =   AC::SERVER_TIME;
    	
        $key    =   $this->feedKeyPrefix. $uid;
        $result =   Storage::addData($key, $data);
        
    }/*}}}*/
    
    #添加转发我的日志信息
    public function setRepostInfo($feedInfo,$info)/*{{{*/
    {
        isset($feedInfo['bodyId'])      &&  $data['bodyId']     =   $feedInfo['bodyId'];
        isset($feedInfo['content'])     &&  $data['content']    =   $feedInfo['content'];
        isset($feedInfo['subType'])     &&  $data['subType']    =   $feedInfo['subType'];
        isset($feedInfo['rUid'])        &&  $data['rUid']       =   $feedInfo['rUid'];
        isset($feedInfo['rNickname'])   &&  $data['rNickname']  =   $feedInfo['rNickname'];
        isset($feedInfo['parentId'])    &&  $data['parentId']   =   $feedInfo['parentId'];
        
        $userInfo = $this->autoUidModel->getUserInfo($info['zfUid']);
        
        $data['uid']            =   $info['zfUid'];
        $data['eUid']           =   $feedInfo['eUid'];
        $data['eNickname']      =   $feedInfo['eNickname'];
        $data['authorUid']      =   $userInfo['uid'];
        $data['authorNickname'] =   $userInfo['nickname'];
        $data['type']           =   AC::FEED_REPOST;
        $data['time']           =   AC::SERVER_TIME;
        
        $key    =   $this->feedKeyPrefix. $info['zfUid'];
        $result =   Storage::addData($key, $data);
    
    }/*}}}*/

    public function getFeedList($feedInfo)/*{{{*/
    {
        if (empty($feedInfo['uid']))
        {
            AC::$errorNo    =   'FM004';
            return  FALSE;
        }

        $start  =   0;
        $length =   AC::FEED_LIST_DISPLAY_LEN;
        isset($feedInfo['start'])   &&  $start  =   $feedInfo['start'];
        isset($feedInfo['length'])  &&  $length =   $feedInfo['length'];
        if ($start  <   0)  $start  =   0;

        $orderBy=   ' id DESC ';
        if (empty($feedInfo['id'])) $feedInfo['id'] =   0;
        $where  =   ' id > '. $feedInfo['id'];
        
        $key    =   $this->feedKeyPrefix. $feedInfo['uid'].$this->slaveKey;
        $result =   Storage::getConditionManyData($key, $where, $orderBy, $start, $length);
        return  $result;
    }/*}}}*/
    
    // 获取好友的动态
    public function getUserFeedList($feedInfo,$uids='')/*{{{*/
    {
        if (empty($feedInfo['uid']))
        {
            AC::$errorNo    =   'FM004';
            return  FALSE;
        }
    
        $start  =   0;
        $length =   AC::FEED_LIST_DISPLAY_LEN;
        isset($feedInfo['length'])  &&  $length =   $feedInfo['length'];
    
        $orderBy  =   ' id DESC ';
        $page     =   '';
        
        // 分页
        if (intval($feedInfo['id']) > 0 ){
            $page = " id < " .intval($feedInfo['id'])." AND ";
        }
        
        // 好友的动态
        if (isset($feedInfo['followfeed']) && !empty($uids)){
            $fUids = implode(',',$uids);
            $sql  = $page." type in (16,17,18)  AND eUid in({$fUids}) ";
        }
        
        // 我的动态
        if (isset($feedInfo['mefeed'])) {
            $sql  =  $page .' eUid != '. $feedInfo['uid'] .' AND ( rUid = '. $feedInfo['uid'] .' OR authorUid = '. $feedInfo['uid'].' ) ';
        }
        $where  =   $sql;
    
        $key    =   $this->feedKeyPrefix. $feedInfo['uid'].$this->slaveKey;
        $result =   Storage::getConditionManyData($key, $where, $orderBy, $start, $length);
        return  $result;
    }/*}}}*/
    
    public function getUserNoticeListFromRedis($feedInfo){
        if (empty($feedInfo['uid'])){
            AC::$errorNo    =   'FM004';
            return  FALSE;
        }
    
        $start  =   0;
        $length =   AC::FEED_LIST_DISPLAY_LEN;
        isset($feedInfo['length'])  &&  $length =   $feedInfo['length'];
        if($length < 10 || $length > 50){
            $length =   AC::FEED_LIST_DISPLAY_LEN;
        }

        $feedId  = intval($feedInfo['id']);

        $listids = $this->diaryListCacheModel->getUserFeedMeTimeline($feedInfo['uid'], $feedId, $start, $length);
        $noticeList = array();
        foreach ($listids as $feedid){
            $tmp = $this->getFeedInfoByFeedId($feedid);
            if (empty($tmp)){
                continue;
            }
	        $tmp['id']     = $feedid;
            $noticeList[]  = $tmp;
        }
        
        $user_cache = $this->diaryListCacheModel->getUserFeedMeCache($feedInfo['uid']);
        if ((empty($noticeList) && intval($feedId) < 1) || ($user_cache['fdme_upt'] < 1 && intval($feedId) < 1)){
            $noticeList = $this->getUserNoticeListFromMysql($feedInfo['uid'], $feedId, $start, $length);
        }
        
        return  $noticeList;
    }
    
    private function getUserNoticeListFromMysql ($uid, $feedId = 0, $start, $length){
        if (empty($uid)){
            AC::$errorNo    =   'FM004';
            return  FALSE;
        }
        
        $where = array('uid' => $uid);
	$key    =    $this->feedListKeyPrefix. $uid;
        $orderBy=    ' id DESC ';
        $result =    Storage::getConditionManyData($key, $where, $orderBy, $start, $length);
        
        $noticeList = array();
        if (!empty($result)){
            foreach ($result as $value){
                $tmp = $this->getFeedInfoByFeedId($value['type_id']);
                if (empty($tmp)){
                    continue;
                }
                $noticeList[]  = $tmp;
            }
        }
        return  $noticeList;
    }
    
    // 获取好友的动态
    public function getUserFeedListFromRedis($feedInfo)/*{{{*/
    {
        if (empty($feedInfo['uid']))
        {
            AC::$errorNo    =   'FM004';
            return  FALSE;
        }
    
        $start  =   0;
        $length =   AC::FEED_LIST_DISPLAY_LEN;
        isset($feedInfo['length'])  &&  $length =   $feedInfo['length'];
        if($length < 10 || $length > 50){
            $length =   AC::FEED_LIST_DISPLAY_LEN;
        }

        $feedId  = intval($feedInfo['id']);

        // 好友的动态
        if (isset($feedInfo['mefeed'])){
            $listids = $this->diaryListCacheModel->getUserFeedMeTimeline($feedInfo['uid'], $feedId, $start, $length);
        }else{
            $listids = $this->diaryListCacheModel->getUserFeedTimeline($feedInfo['uid'], $feedId, $start, $length);
        }
        $feedList = array();
        foreach ($listids as $feedid){
            $tmp = $this->getFeedInfoByFeedId($feedid);
            if (empty($tmp)){
                continue;
            }
            $feedList[]  = $tmp;
        }
        return  $feedList;
    }/*}}}*/

    public function getFeedInfoByFeedId($feedid){

        $feedInfo = $this->diaryListCacheModel->getFeedInfoCache($feedid);
        if(empty($feedInfo)){
            $feedInfo = $this->getFeedInfoFromDb($feedid);
            if(!empty($feedInfo)){
                $this->diaryListCacheModel->setFeedInfoCache($feedid, $feedInfo);
            }
        }
        $feedInfo['feed_id'] = $feedid;
        if(!empty($feedInfo)){

            return $this->rebuildFeedInfoCache($feedInfo);
        }
        return array();
    }

    public function getFeedInfoFromDb($feedid){
        if (empty($feedid)) return array();
        $code = "FO";
        return  Storage::getDataByBodyid($code, $feedid, ' * ', "feed_id");
    }
	
    private function rebuildFeedInfoCache($data){
        $data['actor']= json_decode($data['actor'], true) ;
        $data['object']= json_decode($data['object'], true) ;
        $result = json_decode($data['extra'], true) ;
        if (!empty($result)){
            $result['id'] = $data['feed_id'];
        }
        return $result;
    }
    
    public function getFeedListUp($feedInfo)/*{{{*/
    {
        if (empty($feedInfo['uid']) ||  empty($feedInfo['id']))
        {
            AC::$errorNo    =   'FM005';
            return  FALSE;
        }

        $start  =   0;
        $length =   AC::FEED_LIST_DISPLAY_LEN;

        $orderBy=   ' id ASC ';
        $where  =   ' id > '. $feedInfo['id'];
        $key    =   $this->feedKeyPrefix. $feedInfo['uid'].$this->slaveKey;
        $result =   Storage::getConditionManyData($key, $where, $orderBy, $start, $length);
        return  $result;
    }/*}}}*/

    public function getFeedListDown($feedInfo)/*{{{*/
    {
        if (empty($feedInfo['uid']) ||  empty($feedInfo['id']))
        {
            AC::$errorNo    =   'FM006';
            return  FALSE;
        }

        $start  =   0;
        $length =   AC::FEED_LIST_DISPLAY_LEN;

        $orderBy=   ' id DESC ';
        $where  =   ' id < '. $feedInfo['id'];
        $key    =   $this->feedKeyPrefix. $feedInfo['uid'].$this->slaveKey;
        $result =   Storage::getConditionManyData($key, $where, $orderBy, $start, $length);
        return  $result;
    }/*}}}*/
    
    public function removeFeed($feedInfo)/*{{{*/
    {
        if (empty($feedInfo['uid']) ||  empty($feedInfo['id']))
        {
            AC::$errorNo    =   'FM006';
            return  FALSE;
        }

        $where  =   array('id'  =>  $feedInfo['id']);
        $key    =   $this->feedKeyPrefix. $feedInfo['uid'];
        $result =   Storage::delConditionData($key, $where);

        return  $result;
    }/*}}}*/
     
    
    /**
     * 重建用户关注时间线
     * @param $info
     */
    public function statRebuildTimeline($uid, $type = AC::FEED_DIARY)/*{{{*/
    {
        $where  =   array('type' => $type);
        $key    =   $this->feedKeyPrefix. $uid.$this->slaveKey;
        $start  =   0;
        $length =   800;
        $orderBy=   ' id desc ';
        $field  =   ' bodyId ';
        $result =   Storage::getFieldsConditionManyData($key,$field, $where, $orderBy, $start, $length);
        if (empty($result)) return false;
        $this->diaryListCacheModel->delFeedTimeline($uid);
        foreach ($result as $key=>$value){
            foreach ($value as $bodyId){
                $this->diaryListCacheModel->addManyFeedTimeline($uid, $bodyId);
            }
        }
        return true;
    }/*}}}*/
    
    
    //从feed表中的数据构建日志摘要
    public function buildFeedItem($data){
    
        $diaryInfo = array();
        $diaryInfo['id']             =    strval($data['id']);
        $diaryInfo['uid']            =    $data['authorUid'];
        $diaryInfo['rBodyId']        =    '0';
        $diaryInfo['rUid']           =    '0';
        $diaryInfo['bodyId']         =    strval($data['bodyId']);
        $diaryInfo['title']          =    '';
        $diaryInfo['abbreviation']   =    '该日记已被删除或转为私密';
        $diaryInfo['secret']         =    '0';
        $diaryInfo['attachmentPath'] =    '';
        $diaryInfo['attachmentList'] =    array();
        $diaryInfo['time']           =    strval($data['time']);
        $diaryInfo['status']         =    strval($data['status']);
        $diaryInfo['type']           =    strval($data['type']);
        $diaryInfo['label']          =    '0';
        $diaryInfo['commentPeople']  =    '0';
        $diaryInfo['viewTimes']      =    '0';
        $diaryInfo['commentTimes']   =    '0';
        $diaryInfo['likeTimes']      =    '0';
        $diaryInfo['shareTimes']     =    '0';
        $diaryInfo['label']          =    '0';
        $diaryInfo['user']             =    $this->autoUidModel->getUserInfo($diaryInfo['uid']);
        if (AC::HOST_UID    !== $diaryInfo['eUid']) {
            unset($diaryInfo['user']['account']);
            unset($diaryInfo['user']['email']);
	    unset($diaryInfo['user']['thirdParty']);
        }
        return $diaryInfo;
    }
    //构建关注列表格式
    public function square($data, $check_host_uid = TRUE)/*{{{*/
    {
        $square    = array();
        // 获取备注名称
        $data['nickname']=    $this->autoUidModel->getRemarkName($data);
        
        $square['eUid']             =    strval($data['uid']);
        $square['eNickname']        =    $data['nickname'];
        $square['bodyId']           =    strval($data['bodyId']);
        $square['type']             =    '1';
        $square['in_review']        =    isset($data['inReview']) ? intval($data['inReview']) : 0;//审核中标识 1
        $square['is_diarytop']      =    isset($data['is_diarytop']) ? intval($data['is_diarytop']) : 0;//点滴置顶标识 1
        $square['time']             =    strval($data['time']);
        $square['label']            =    strval($data['label']);

        $square['id']               =    strval($data['id']);
        $square['detail']           =    $this->diaryListModel->buildDiaryListItem($data, $check_host_uid);

		$connent                    =    UK::get_text($data['abbreviation']);
		$square['content']          =    UK::tipsUpgrade($data['extras'], $connent, 'topicFd');
		$square['content']          =   Emotion::resourcesToNull($square['content']);
        // 是否喜欢
        $square['detail']['is_favor']         =    strval($data['is_favor']);
        $square['detail']['user']['nickname'] = $this->autoUidModel->getRemarkName($square['detail']['user']);
        $square['eNickname'] = $square['detail']['user']['nickname'];
        
        $square['retweeted_status'] =    $this->diaryListModel->manipulationListData($data);
        
        // 判断是否老版本
        if (intval($square['detail']['rUid']) > 0 && intval($square['detail']['rBodyId']) > 0 && AC::$userVersion == '1'){
            $square['content'] = $this->iosRepostConnent($square);
            $square['detail']['abbreviation'] = $this->iosRepostConnent($square);
            if (!is_object($square['retweeted_status'])){
                $square['detail']['attachmentPath'] = $square['retweeted_status']['attachmentPath'];
                $square['detail']['attachmentList'] = $square['retweeted_status']['attachmentList'];
            }
        }
        $square['attachmentList'] = $square['detail']['attachmentList'];
        $square['content'] = $square['detail']['abbreviation'] = UK::tipsUpgrade($square['detail']['voiceList'], $square['content'], 'voice');
        if (!empty($square['detail']['videoList'])){
            $square['content'] = $square['detail']['abbreviation']   =    UK::tipsUpgrade($square['detail']['videoList'], $square['content'], 'video');
            AC::$video_version==0 && $square['detail']['attachmentPath'] = '';
        }

        // 过滤表情#号
        $square['detail']['abbreviation']   =    Emotion::emotionToCharacter($square['detail']['abbreviation']);
        
        //lbs
        $square['detail']['geo'] = (Object) array();
		if(!empty(UK::getstr($data['geo']['name'], 50, '', 1)) && !empty($data['geo']['citycode']) ){
			$square['detail']['geo']=$data['geo'];
		}

		//点滴投票
			$vote = $this->voteModel->getVoteInfo($data['bodyId'], $data['uid'], $data['vote'], AC::HOST_UID);
			$square['detail']['vote'] = $vote;
        // 精选判断
//        $square['detail']['essence'] = $this->diaryListModel->checkIsHotDiaryOfList($data['bodyId']);
        $square['detail']['essence'] = $this->diaryListModel->checkIsHotDiaryInTopic($data['topics'], $data['bodyId']);

        //置顶
        $topic = json_decode($data['topics'], true);
        $square['detail']['display'] = $this->diaryListModel->checkIsTopDiaryOfDetail($topic['gid'], $data['bodyId']);

        $square['detail']['topic'] = $this->diaryListModel->getDiaryTopic($data['topics']);

        $extras = json_decode($data['extras'], true);
        $square['source'] = !empty($extras['source']) ? $extras['source'] : '';
        $square['vip']['cardbg'] = !empty($extras['vip']['cardbg']) ? AC::getProtocolUriByOS(AC::$cdn_url_d).$extras['vip']['cardbg'] : '';
		$square['detail']['original'] = $extras['original'] ? $extras['original'] : '';

		//版本控制
        $product_version=    AC::$appInfoList[1];
        $os             =    strtolower(AC::$appInfoList[2]);
        $version = array(
            'android'          =>  '5.50',
            'ios'              =>  '5.5.0',
        );
        $check = version_compare($product_version, $version[$os],  '<=');
        //如果存在分享且分享的内容是文章
        if(!$check && isset($square['detail']['url_struct'][0]['url_type'])  && $square['detail']['url_struct'][0]['url_type'] == 'article') {
            // 字符串截取（点滴列表中的内容被截取）
            $articleSummary = $square['detail']['url_struct'][0]['url_content'];
            $contentTmp = UK::getstr($articleSummary, 500, '...');
            //如果点滴的摘要和文章的摘要一样则不再显示
            if($square['detail']['abbreviation'] == $contentTmp  || $square['detail']['abbreviation'] == '分享文章'){
                $square['content'] = $square['detail']['abbreviation'] = '';
            }
            //不返回话题
            $square['detail']['topic'] = [];
        }
        if($check && isset($square['detail']['url_struct'][0]['url_type']) && $square['detail']['url_struct'][0]['url_type'] == 'web') {
            if(strlen($square['detail']['url_struct'][0]['url_title']) > 40){
                $square['detail']['url_struct'][0]['url_title'] = UK::getstr($square['detail']['url_struct'][0]['url_title'], 40, '...');
            }
            $square['detail']['url_struct'][0]['url_content'] = UK::getstr($square['detail']['url_struct'][0]['url_content'], 40);
        }
        $square['content'] = $square['detail']['abbreviation'] = UK::getstr($square['detail']['abbreviation'], 320, '...');

        return $square;
    }



    /**
     * 构建喜欢数据格式
     * @param unknown $data
     * @param unknown $feedLikes
     * @return Ambigous <StdClass, boolean, unknown, Ambigous, string, NULL>
     */
    public function likesData($data, $feedLikes){
        $likes    = array();
        if (isset($feedLikes['lUid']) && isset($feedLikes['lNickname'])){
            $feedLikes['eUid']      = $feedLikes['lUid'];
            $feedLikes['eNickname'] = $feedLikes['lNickname'];
        }
        // 获取备注名称
        $tmp['uid']       =    $feedLikes['eUid'];
        $tmp['nickname']  =    $feedLikes['eNickname'];
        $feedLikes['eNickname']=    $this->autoUidModel->getRemarkName($tmp);
        
        $likes['eUid']             =     $feedLikes['eUid'];
        $likes['eNickname']        =     $feedLikes['eNickname'];
        $likes['bodyId']           =     strval($feedLikes['bodyId']);
        $likes['type']             =     strval($feedLikes['type']);
        $likes['time']             =     strval($feedLikes['time']);
        $likes['label']            =     '0';
        $likes['content']          =     $feedLikes['content'];
        $likes['id']               =     strval($feedLikes['id']);
    
        $likes['detail']           =    $this->diaryListModel->buildDiaryListItem($data);
        $likes['detail']['id']     =    $feedLikes['id'];
        $likes['retweeted_status'] =    $this->diaryListModel->manipulationListData($data);
        $likes['user'] = NULL;
        if (!empty(AC::$user[$feedLikes['eUid']])){
            $likes['user']             =     AC::$user[$feedLikes['eUid']];
        }
        if (empty($likes['user'])){
	    $userInfo       =    $this->autoUidModel->getUserInfo($feedLikes['eUid']);
            $likes['user']  =    $this->autoUidModel->checkIsMe($userInfo);
            AC::$user[$feedLikes['eUid']] = $likes['user'];
        }
       
        return $likes;
    }
    /**
     * 将数据库中的喜欢数据重组
     * @param unknown $result
     * @return multitype:string number unknown
     */
    public function feedLikesData($data){
        $feedInfo    = array();
        $data['authorUid']            =    $data['uid'];
        if (isset($data['lUid']) && isset($data['lNickname'])){
            $data['eUid']      =    $data['lUid'];
            $data['eNickname'] =    $data['lNickname'];
            $data['authorUid'] =    $data['eUid'];
        }
        // 获取备注名称
        $tmp['uid']       =    $data['eUid'];
        $tmp['nickname']  =    $data['eNickname'];
        $data['eNickname']=    $this->autoUidModel->getRemarkName($tmp);
        
        $feedInfo['eUid']             =    strval($data['eUid']);
        $feedInfo['eNickname']        =    $data['eNickname'];
        $feedInfo['bodyId']           =    strval($data['bodyId']);
        $feedInfo['type']             =    strval($data['type']);
        $feedInfo['time']             =    strval($data['time']);
        $feedInfo['label']            =    '0';
        $feedInfo['content']          =    $data['content'];
        $feedInfo['id']               =    strval($data['id']);
        $feedInfo['detail']           =    $this->buildFeedItem($data);
        $feedInfo['retweeted_status'] =    (Object) array();
	$userInfo       =    $this->autoUidModel->getUserInfo($data['eUid']);
        $feedInfo['user']  =    $this->autoUidModel->checkIsMe($userInfo);
        
        return $feedInfo;
    }
 
    /**
     * 重构动态的头部数据
     * @param unknown $data
     * @return multitype:NULL unknown string
     */
    public function rebuildFeedList($data){
        $feedInfo = array();
        
        // 获取备注名称
        $tmp['uid']       =    $data['eUid'];
        $tmp['nickname']  =    $data['eNickname'];
        
        $feedInfo['id']               =    strval($data['id']);
        $feedInfo['eUid']             =    strval($data['eUid']);
        $feedInfo['eNickname']        =    $data['eNickname'];
        $feedInfo['rUid']             =    empty($data['rUid'])      ? strval($data['authorUid'])     : strval($data['rUid']);
        $feedInfo['rNickname']        =    empty($data['rNickname']) ? $data['authorNickname']  : $data['rNickname'];
        $feedInfo['rNickname']        =    $this->autoUidModel->getRemarkName(array('uid' => $feedInfo['rUid'], 'nickname' => $feedInfo['rNickname']));
        $feedInfo['parentId']         =    strval($data['parentId']);
        $feedInfo['position']         =    strval($data['position']);
        $feedInfo['bodyId']           =    empty($data['bodyId'])    ? ''  : strval($data['bodyId']);
        $feedInfo['type']             =    strval($data['type']);
        $feedInfo['time']             =    strval($data['time']);
        $feedInfo['subType']          =    strval($data['subType']);
        $feedInfo['content']          =    $data['content'];
	$userInfo       =    $this->autoUidModel->getUserInfo($data['eUid']);
        $feedInfo['user']  =    $this->autoUidModel->checkIsMe($userInfo);
        $feedInfo['user']['nickname'] =    $this->autoUidModel->getRemarkName($feedInfo['user']);
        return $feedInfo;
    }
    /**
     * 重构评论我的数据
     * @param unknown $feedDetail
     * @param string $data
     * @return multitype:StdClass NULL unknown |Ambigous <StdClass, boolean, unknown>
     */
    public function rebuildCommentMeData($feedDetail, $data=''){
        
        $comment = array();
        // 获取备注名称
        $tmp['uid']    =    $feedDetail['cUid'];
        $tmp['nickname'] =  $feedDetail['cNickname'];
        $feedDetail['cNickname']= $this->autoUidModel->getRemarkName($tmp);
        
        $comment['id']         = strval($feedDetail['id']);
        $comment['eUid']       = strval($feedDetail['cUid']);
        $comment['eNickname']  = $feedDetail['cNickname'];
        $comment['rUid']       = intval($feedDetail['rUid']) > 0  ?  strval($feedDetail['rUid']) : strval($feedDetail['uid']) ;
        $comment['rNickname']  = empty($feedDetail['rNickname'])  ? $feedDetail['nickname'] : $feedDetail['rNickname'];
        $comment['parentId']   = strval($feedDetail['parentId']);
        $comment['bodyId']     = strval($feedDetail['bodyId']);
        $comment['type']       = '17';
        $comment['content']    = $feedDetail['content'];
        $comment['time']       = strval($feedDetail['time']);
        
        if (empty($data)){
            $user             =    $this->autoUidModel->getUserInfo($comment['eUid']);
            $comment['user']  =    $this->autoUidModel->checkIsMe($user);
            
            $feedDetail['type']            =    '17';
            $feedDetail['authorUid']       =    intval($feedDetail['rUid']) > 0 ? $feedDetail['rUid']  : $feedDetail['uid'] ;
            $comment['detail']             =    $this->buildFeedItem($feedDetail);
            $comment['retweeted_status']   =    (Object) array();
            return $comment;
        }
        
        $this->commentsData($comment, $data);
        // 备注
        $comment['eNickname'] = $comment['user']['nickname'] = $this->autoUidModel->getRemarkName(array('uid'=>$comment['eUid'],'nickname'=>$comment['eNickname']));
        
        return $comment;
    }
    /**
     * 重构我评论的数据
     * @param unknown $feedDetail
     * @param string $data
     * @return multitype:StdClass NULL unknown |Ambigous <StdClass, boolean, unknown>
     */
    public function rebuildMeCommentData($feedDetail, $data=''){
        $comment = array();
        // 获取备注名称
        $feedDetail['nickname']= $this->autoUidModel->getRemarkName($feedDetail);
        $comment['id']         = strval($feedDetail['id']);
        $comment['eUid']       = strval($feedDetail['uid']);
        $comment['eNickname']  = $feedDetail['nickname'];
        $comment['rUid']       = strval($feedDetail['rUid']);
        $comment['rNickname']  = $this->autoUidModel->getRemarkName(array('uid'=>$feedDetail['rUid'],'nickname'=>$feedDetail['rNickname']));
        $comment['parentId']   = strval($feedDetail['parentId']);
        $comment['bodyId']     = strval($feedDetail['bodyId']);
        $comment['type']       = strval($feedDetail['type']);
        $comment['content']    = $feedDetail['content'];
        $comment['time']       = strval($feedDetail['time']);
        
        if (empty($data)){
            $feedDetail['authorUid']       =    $feedDetail['cUid'];
            $feedDetail['type']            =    '17';
            $comment['detail']             =    $this->buildFeedItem($feedDetail);
            $comment['retweeted_status']   =    (Object) array();
            $user                          =    $this->autoUidModel->getUserInfo($comment['eUid']);
            $comment['user']               =    $this->autoUidModel->checkIsMe($user);
            return $comment;
        }
        
        $this->commentsData($comment, $data);
        
        return $comment;
    }
    
    private function commentsData(&$comment, $data){
        $comment['user'] = NULL;
        // 将已经存在的用户缓存直接使用,减少了对redis的读取
        if (!empty(AC::$user[$comment['eUid']])){
        
            $comment['user']             =     AC::$user[$comment['eUid']];
        
        }
        if ( empty($comment['user'])){
            $user             =    $this->autoUidModel->getUserInfo($comment['eUid']);
            $comment['user']  =    $this->autoUidModel->checkIsMe($user);
            
            AC::$user[$comment['eUid']]  = $comment['user'];
        }
        
        $comment['detail']           =    $this->diaryListModel->buildDiaryListItem($data);
        $comment['detail']['id']     =    $comment['id'];
        $comment['retweeted_status'] =    $this->diaryListModel->manipulationListData($data);
    }
    
    /**
     * 判断是否老版本
     * @param unknown $info
     * @return string
     */
    public function iosRepostConnent($info){
        if (!is_object($info['retweeted_status'])){
            $connent = '转发了 「'.$info['retweeted_status']['nickname']."」的日记.\r\n";
            $title = $info['retweeted_status']['abbreviation'];
            if (!empty($info['retweeted_status']['title'])){
                $title   = '《'.$info['retweeted_status']['title']."》\r\n".$info['retweeted_status']['abbreviation'];
            }
            return $connent.$title;
        }
        $connent = $info['eNickname']."所转发的原日记已被删除或转为私密";
        return $connent;
    }
    
    /**
     * 判断是否老版本
     * @param unknown $info
     * @return string
     */
    public function iosRepostConnentByDetail($info){
        if (!is_object($info['retweeted_status'])){
            $connent = '转发了 「'.$info['retweeted_status']['listInfo']['nickname']."」 的日记.\r\n";
            $title = $info['retweeted_status']['bodyInfo']['content'];
            if (!empty($info['retweeted_status']['listInfo']['title'])){
                $title   = '《'.$info['retweeted_status']['listInfo']['title']."》\r\n".$info['retweeted_status']['bodyInfo']['content'];
            }
            return $connent.$title;
        }
        $connent = $info['listInfo']['abbreviation']."\r\n 转发的原日记已被删除或转为私密";
        return $connent;
    }
    
    /**
     * 判断是否老版本
     * @param unknown $info
     * @return string
     */
    public function iosRepostConnentByNewDetail($info){
        if (!is_object($info['retweeted_status'])){
            $connent = '转发了 「'.$info['retweeted_status']['user']['nickname']."」 的日记.\r\n";
            $title = $info['retweeted_status']['content'];
            if (!empty($info['retweeted_status']['title'])){
                $title   = '《'.$info['retweeted_status']['title']."》\r\n".$info['retweeted_status']['content'];
            }
            return $connent.$title;
        }
        $connent = '转发的原日记已被删除或转为私密';
        return $connent;
    }
}


